#!/usr/bin/perl -w

use strict;
use warnings;
use utf8;
use open ':encoding(utf8)';
use Algorithm::Diff;
use Unicode::Normalize qw(decompose);
use vars qw($dbh);
require "../conn.pl";

print "##############################\n";
print "# Creating Database          #\n";
print "##############################\n";

my @files = qw(
	schema.sql
	procedures.sql
	data.language.sql
	data.license.sql
);
foreach(@files){
	print "- $_\n";
	#open IN, $_;
	#my $s = join '', <IN>;
	#close IN;
	#$dbh->do($s);
	system("mysql -u root < $_");
}
#system("mysql -u root < " . join ', ', @files);


1;

#print "- schema.sql\n";
#system('mysql -u root < schema.sql');
#print "- procedures.sql\n";
#system('mysql -u root < procedures.sql');
#print "- data.language.sql\n";
#system('mysql -u root < data.language.sql');
#print "- data.license.sql\n";
#system('mysql -u root < data.license.sql');


#use DBI;
#use strict;
#use warnings;
#use utf8;
#use open ':encoding(utf8)';
#use vars qw($dbh);
#require('../conn.pl');


#
#{
#	my @tables = qw(edition   work   i18n   language   ref_system   edition_token   token   i18n_textdomain   lexeme   note   user   note_token   note_user   ref   token_origin   token_origin_rating   token_parsing   user_language);
#	$dbh->prepare("SET FOREIGN_KEY_CHECKS = 0;")->execute();
#	foreach(@tables){
#		$dbh->prepare("DELETE FROM $_")->execute();
#		$dbh->prepare("ALTER TABLE $_ AUTO_INCREMENT = 1")->execute();
#	}
#	$dbh->prepare("SET FOREIGN_KEY_CHECKS = 1;")->execute();
#
#	#system("mysql -u root < structure.sql");
#	system("mysql -u root < data.sql");
#}
#
#
#chdir('../texts/');
#foreach my $dir (glob('*')){
#	next if (not -d $dir) || (!-e "$dir/make.pl");
#	chdir $dir;
#	
#	print "$dir\n";
#	require('make.pl');
#	
#	chdir '..';
#	next;
#	
#	
#	#chdir $dir;
#	#my $file = $dir . "_utf8.txt";
#	#die "Not found: $file" if(!-e $file);
#	#
#	#my $count = 0;
#	#
#	#open MS, "$file";
#	#while(<MS>){
#	#	next if /^#/;
#	#	chomp;
#	#	$count++;
#	#	
#	#	s/^(.+)\t+//;
#	#	my $ref = $1;
#	#	
#	#	my @parsings = /((?:G\d+\s+)?[\-0-9A-Z]+)/g;
#	#	s/(?:G\d+\s+)?[\-0-9A-Z]+//g;  #/G1080 -3S/
#	#	s/\s+/ /g;
#	#	#saysay OUT "$_";
#	#	
#	#	if($count == 100){
#	#		say $ref;
#	#		say OUT;
#	#		say join ', ', @parsings;
#	#		last;
#	#	}
#	#}
#	#
#	#
#	#
#	#chdir '..';
#}
#
#1;



#my $dbh = DBI->connect("DBI:mysql:open_scriptures2:localhost", 'root', '');
#
#my $sqlQuery = $dbh->prepare("show tables") or die $dbh->errstr;
#my $rv = $sqlQuery->execute or die $sqlQuery->errstr;
#
#while(@row = $sqlQuery->fetchrow_array()) {
#	my $tables = $row[0];
#	print "$tables\n";
#}
#
#$rv = $sqlQuery->finish;
#exit(0);